<template>
	<view class="template-course tn-safe-area-inset-bottom">
		<view class="lunbotu">
			<swiper class="card-swiper" :circular="true" :autoplay="true" duration="500" style="500rpx"
				@change="cardSwiper">
				<swiper-item v-for="(item,index) in swiperList" :key="index">
					<view class="swiper-item image-banner">
						<image :src="item.image" mode="aspectFill"></image>
					</view>
				</swiper-item>
			</swiper>

			<view class="indication">
				<block v-for="(item,index) in swiperList" :key="index">
					<view class="spot" :class="cardCur==index?'active':''"></view>
				</block>
			</view>
		</view>

		<!-- <view class="tn-flex tn-flex-row-between tn-margin tea-user__wrap">

			<view class="tn-flex-3 tn-padding tea-radius tn-bg-white tea-shadow" style="margin-right: 30rpx;">
				<view class="tn-flex">
					<view class="tn-flex tn-flex-row-center tn-flex-col-center">
						<view class="user-avatar">
							<tn-avatar :src="userInfo.avatar" size="lg" imgMode="scaleToFill"></tn-avatar>
						</view>
						<view class="tn-padding-right tn-text-ellipsis tn-text-left">
							<view class="tn-padding-right tn-padding-left-sm tn-color-black tn-text-bold">
								{{userInfo.nickname}}
							</view>
							<view class="tn-padding-right tn-padding-left-sm tn-padding-top-xs tn-color-gray tn-text-sm">
								{{ userInfo.remark }}</view>
						</view>
					</view>
				</view>
			</view>

			<view class="tn-flex-1 justify-content-item tn-padding tn-text-center tea-radius tn-bg-white tea-shadow"
				@click="tn('/subpages/user/set')">
				<view class="">
					<text class="tn-icon-edit tn-text-xl"></text>
				</view>
				<view class=" tn-padding-top-xs">
					信息
				</view>
			</view>
		</view> -->


		<view class="">

			<!-- 方式12 start-->
			<!-- <view class="tn-flex tn-margin" style="padding-top: 15rpx;">
				<view class="tn-flex-1 tea-shadow tea-radius tn-bg-white" style="margin-right: 15rpx;padding: 40rpx 0;"
					@click="tn('/subpages/exam/rank/list')">
					<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
						<view
							class="icon12__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-main-gradient-blue--light tn-color-blue">
							<view class="tn-icon-trophy tn-three"></view>
						</view>
						<view class="tn-text-center">
							<view class="tn-text-ellipsis tn-text-xl tn-text-bold">答题排行</view>
							<view class="tn-text-ellipsis tn-color-gray--dark tn-padding-top-sm">全站答题排行</view>
						</view>
					</view>
				</view>
				<view class="tn-flex-1 tea-shadow tea-radius tn-bg-white" style="margin-left: 15rpx;padding: 40rpx 0;"
					@click="tn('/subpages/user/index')">
					<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
						<view
							class="icon12__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-main-gradient-blue--light tn-color-blue">
							<view class="tn-icon-menu-match tn-three"></view>
						</view>
						<view class="tn-text-center">
							<view class="tn-text-ellipsis tn-text-xl tn-text-bold">个人中心</view>
							<view class="tn-text-ellipsis tn-color-gray--dark tn-padding-top-sm">瞧瞧你的主页</view>
						</view>
					</view>
				</view>
				
			</view> -->

			<!-- 中间卡片开始 -->
			<view class="tn-info__container tn-flex tn-flex-wrap tn-flex-col-center tn-flex-row-between tn-margin"
				style="padding-top: 15rpx;">
				<block v-for="(item, index) in tuniaoData" :key="index">
					<view
						class="tn-info__item tn-flex tn-flex-direction-row tn-flex-col-center tn-flex-row-between tn-color-white tea-shadow"
						@click="tn(item.url)">
						<view
							class="tn-info__item__left tn-flex tn-flex-direction-row tn-flex-col-center tn-flex-row-left">
							<view class="tn-info__item__left--icon tn-flex tn-flex-col-center tn-flex-row-center"
								:class="[`tn-color-${item.color}--disabled`]">
								<view :class="[`tn-icon-${item.icon}`]"></view>
							</view>
							<view class="tn-info__item__left__content">
								<view
									class="tn-info__item__left__content--title tn-text-bold tn-text-xl tn-color-black tn-color-black-title">
									{{ item.title }}
								</view>
								<view class="tn-info__item__left__content--data tn-padding-top-xs tn-color-black">
									{{ item.value }}
									<text class="tn-padding-left-xs"></text>
								</view>
							</view>
						</view>
						<view class="tn-info__item__right">
							<view class="tn-info__item__right--icon">
								<view :class="[`tn-icon-${item.icon}`]"></view>
							</view>
						</view>
					</view>
				</block>
			</view>
			<view>
				<view class="choose-tab">
					<view class="choose-tab-item" :class="chooseTab == 0 ? 'active' : ''" data-choose="0"
						@click="clickTab">最新动态</view>
					<view class="choose-tab-item" :class="chooseTab == 1 ? 'active' : ''" data-choose="1"
						@click="clickTab">官方网站</view>

				</view>

				<view class="content">
					<view :style="chooseTab != 0 ? 'display:none' : ''">
						<view class="news_list" v-for="(item,index) in zxxwList" :key="item.id"
							@click="newsDetail(item.id)">
							<view class="news_list_left">
								<img :src="item.image" alt="" srcset="" />
							</view>
							<view class="news_list_right">
								<view class="news_list_head">{{item.title}}</view>
								<view class="news_list_con">{{item.desc}}
								</view>
								<view class="news_list_bottom">
									<span v-if="item.author!=''" style="margin-right: 30rpx;">{{item.author}}</span>
									<span>{{Date.parse(new Date(item.create_time)) | dateFormat}}</span>
								</view>
							</view>
						</view>
					</view>
					<view :style="chooseTab != 1 ? 'display:none' : ''">
						<view class="news_list news_list2" v-for="(item,index) in gfwzList" :key="item.id"
							@click="gfwz(item.desc)">
							<view class="news_list_left news_list_left2">
								<img :src="item.image" alt="" srcset="" />
							</view>
							<view class="news_list_right2">
								<view class="news_list_head2">{{item.title}}</view>
								<view class="news_list_con2">{{item.desc}}</view>
							</view>
						</view>
					</view>
				</view>

			</view>
		</view>
		<!-- 中间卡片结束 -->

		<!-- 文档开始 -->
		<!-- <view class="tn-margin" style="box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.07);">
				<view class="tn-flex-row-between tn-strip-top tn-padding tn-strip-bottom-min tn-margin-top-xs">
					<view class="justify-content-item">
						<view class="tn-text-bold tn-text-lg">
							{{articleList.title}}
						</view>
					</view>
				</view>
				<view class="tn-flex tn-flex-row-between tn-strip-bottom-min tn-padding"
					style="padding-top: 10rpx;padding-bottom: 20rpx;" v-for="(item1, index) in articleList.list"
					:key="index" @click="tn('/subpages/article/content?uid=' + item1.uid)">
					<view class="justify-content-item">
						<view class="tn-text-df">
							{{ item1.title }}
						</view>
					</view>
				</view>
			</view> -->
		<!-- 文档结束 -->

	</view>

	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import {
		getUserBasicInfoNoAuth,
		getNewsList
	} from "@/utils/api/user.js"
	export default {
		name: 'TemplateCourse',
		mixins: [template_page_mixin],
		filters:{
			dateFormat(originVal){
				const dt = new Date(originVal)
						 
				const y = dt.getFullYear()
				const m = (dt.getMonth() + 1 + '').padStart(2, '0')
				const d = (dt.getDate() + '').padStart(2, '0')
				const hh = (dt.getMonth() + '').padStart(2, '0')
				const mm = (dt.getMinutes() + '').padStart(2, '0')
				const ss = (dt.getSeconds() + '').padStart(2, '0')
						 
				return `${y}-${m}-${d}  ${hh}:${mm}`
			}
		},
		data() {
			return {
				// 最新新闻
				zxxwList: [],
				// 官方网站
				gfwzList: [],
				chooseTab: 0, //当前选中的选项卡：默认选中第一个~
				cardCur: 0,
				swiperList: [{
					id: 0,
					type: 'image',
					url: 'https://imgcdn.tutudati.com/202309122353528.jpg',
				}, {
					id: 1,
					type: 'image',
					url: 'https://imgcdn.tutudati.com/202309122353596.jpg',
				}, {
					id: 2,
					type: 'image',
					url: 'https://imgcdn.tutudati.com/202309122353612.jpg',
				}, {
					id: 3,
					type: 'image',
					url: 'https://imgcdn.tutudati.com/202309122353612.jpg',
				}, {
					id: 4,
					type: 'image',
					url: 'https://imgcdn.tutudati.com/202309122353630.jpg',
				}],
				tuniaoData: [{
						title: '报名咨询',
						icon: 'order-fill',
						color: 'red',
						value: '报名咨询',
						url: '/subpages/web/bmzx/bmzx'
					},
					{
						title: '我的学习',
						icon: 'tag-fill',
						color: 'blue',
						value: '海量题库练习',
						url: '/subpages/exam/list/list'
					},
					{
						title: '网站/公众号',
						icon: 'tip-fill',
						color: 'green',
						value: '了解答题规范',
						url: '/subpages/web/web/index'
					},
					// {
					// 	title: '公众号',
					// 	icon: 'tip-fill',
					// 	color: 'green',
					// 	value: '了解答题规范',
					// 	url: '/subpages/help/content?uid=542677197699339071'
					// },
					// 源码
					{
						title: '个人中心',
						icon: 'order-fill',
						color: 'red',
						value: '参与活动答题',
						url: '/subpages/user/index'
					}
					// {
					// 	title: '题库练习',
					// 	icon: 'tag-fill',
					// 	color: 'blue',
					// 	value: '海量题库练习',
					// 	url: '/subpages/exam/list/list'
					// },
					// {
					// 	title: '答题说明',
					// 	icon: 'tip-fill',
					// 	color: 'green',
					// 	value: '了解答题规范',
					// 	url: '/subpages/help/content?uid=542677197699339071'
					// }
					// {
					// 	title: '创建答题',
					// 	icon: 'identity-fill',
					// 	color: 'teal',
					// 	value: '寻求合作',
					// 	url: '/subpages/help/content?uid=535853809962432024'
					// },
					// {
					// 	title: '关于兔兔',
					// 	icon: 'bookmark-fill',
					// 	color: 'orange',
					// 	value: '了解更多',
					// 	url: '/subpages/help/content?uid=535853725114657278'
					// },
					// {
					// 	title: '兔兔社群',
					// 	icon: 'wechat-fill',
					// 	color: 'aquablue',
					// 	value: '官方沟通群',
					// 	url: '/subpages/help/content?uid=542754200506571780'
					// }
				],
				articleList: {
					uid: "",
					title: "答题技巧",
					list: [{
							uid: "535843466751545307",
							title: "PHPPHP三大主流框架实现统一日志功能",
						},
						{
							uid: "535847751672867770",
							title: "PHPGo语言中的内存逃逸问题分析与解决",
						},
						{
							uid: "535849796574073086",
							title: "PHPGo语言切片底层原理深度剖析",
						},
					],
				},
				userInfo: {
					nickname: '匿名用户',
					avatar: 'https://imgcdn.tutudati.com/xiaomai1.jpg',
					remark: "兔兔知识竞赛活动程序",
				},
				sn: '',
				channelCode: '',
				avatarList: [{
					url: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png'
				}, {
					url: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png'
				}, {
					url: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png'
				}]
			}
		},
		onLoad(params) {
			this.sn = params.shareSn || ''
			this.channelCode = params.channelCode || ''
			uni.setStorageSync("sn", this.sn)
			uni.setStorageSync("channel_code", this.channelCode)
		},
		onShow(params) {
			this.getUserAvatarInfo()
			this.getNews()
			this.getGuanwang()
			this.getLunBoTu()
		},

		methods: {
			getLunBoTu() {
				let _this = this
				uni.request({
					url: _this.$url + '/index/config/getBanner',
					method: 'GET',
					data: {
						platform: 'wechat_mini',
						position: 'min_home'
					},
					success(res) {
						console.log(res)
						_this.swiperList = res.data.data
					}
				})
			},
			// 获取首页最新新闻
			getNews() {
				let _this = this
				uni.request({
					url: _this.$url + '/index/index/getNewsList',
					method: 'GET',
					data: {
						type: 'zxxw',
						row: 10,
						page: 1
					},
					success(res) {
						console.log(res)
						_this.zxxwList = res.data.data.list
					}
				})
			},
			// 获取首页官网
			getGuanwang() {
				let _this = this
				uni.request({
					url: _this.$url + '/index/index/getNewsList',
					method: 'GET',
					data: {
						type: 'gfwz',
						row: 10,
						page: 1
					},
					success(res) {
						console.log(res)
						_this.gfwzList = res.data.data.list
					}
				})
			},

			// 跳转到外部网站详情页
			gfwz(data) {
				// uni.navigateTo({
				// 	url: '/pages/home/home/webpage/webpage?detail=' + encodeURIComponent(JSON.stringify(data))
				// })
			},
			newsDetail(id) {
				uni.navigateTo({
					url: '/pages/home/home/newsDetails/newsDetails?id=' + id
				})
			},
			getUserAvatarInfo() {
				getUserBasicInfoNoAuth().then(res => {
					if (res.code === 100) {
						this.userInfo = res.data
					}
				})
			},
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},
			tn(e) {
				this.$func.navigatorTo(e)
			},
			clickTab: function(e) { //点击切换
				this.chooseTab = e.target.dataset.choose;

				//如果是微信小程序，可使用该方法改变当前设置的值
				/*this.setData({
				    chooseTab: e.target.dataset.choose
				})*/
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 头像 start*/
	.user-avatar {
		width: 90rpx;
		height: 90rpx;
		border-radius: 50%;
		overflow: hidden;
	}

	/* 内容布局 start*/
	.tea-shadow {
		box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	.tea-user {

		&__wrap {
			position: relative;
			z-index: 1;
			margin: 20rpx 30rpx;
			margin-top: -80rpx;
		}
	}

	.tea-radius {
		border-radius: 15rpx;
	}

	/* 轮播视觉差 start */
	.card-swiper {
		height: 400rpx !important;
	}

	.card-swiper swiper-item {
		width: 750rpx !important;
		left: 0rpx;
		box-sizing: border-box;
		// padding: 0rpx 30rpx 90rpx 30rpx;
		overflow: initial;
	}

	.card-swiper swiper-item .swiper-item {
		width: 100%;
		display: block;
		height: 100%;
		transform: scale(1);
		transition: all 0.2s ease-in 0s;
		overflow: hidden;
	}

	.card-swiper swiper-item.cur .swiper-item {
		transform: none;
		transition: all 0.2s ease-in 0s;
	}

	.image-banner {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.image-banner image {
		width: 100%;
		height: 100%;
	}

	/* 轮播指示点 start*/
	.indication {
		z-index: 9999;
		width: 100%;
		height: 36rpx;
		position: absolute;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}

	.spot {
		background-color: #FFFFFF;
		opacity: 0.6;
		width: 10rpx;
		height: 10rpx;
		border-radius: 20rpx;
		// top: -130rpx;
		margin: 0 8rpx !important;
		position: relative;
	}

	.spot.active {
		opacity: 1;
		width: 30rpx;
		background-color: #FFFFFF;
	}

	/* 图标容器12 start */
	.tn-three {
		position: absolute;
		top: 48%;
		right: 50%;
		bottom: 50%;
		left: 52%;
		transform: translate(-38rpx, -16rpx) rotateX(0deg) rotateY(10deg) rotateZ(-20deg);
		text-shadow: -1rpx 2rpx 0 #f0f0f0, -2rpx 4rpx 0 #f0f0f0, -10rpx 20rpx 30rpx rgba(0, 0, 0, 0.2);
	}

	.icon12 {
		&__item {
			width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 100rpx;
				height: 100rpx;
				font-size: 60rpx;
				border-radius: 50%;
				margin-bottom: 18rpx;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;
					background-image: url(https://tnuiimage.tnkjapp.com/cool_bg_image/icon_bg.png);
				}
			}
		}
	}

	/* 业务展示 start */
	.tn-info {

		&__container {
			margin-top: 10rpx;
			margin-bottom: 50rpx;
		}

		&__item {
			width: 48%;
			margin: 15rpx 0rpx;
			padding: 40rpx 30rpx;
			border-radius: 15rpx;


			position: relative;
			z-index: 1;

			&::after {
				content: " ";
				position: absolute;
				z-index: -1;
				width: 100%;
				height: 100%;
				left: 0;
				bottom: 0;
				border-radius: inherit;
				opacity: 1;
				transform: scale(1, 1);
				background-size: 100% 100%;
				background-image: url(https://tnuiimage.tnkjapp.com/cool_bg_image/6.png);
			}

			&__left {

				&--icon {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
					font-size: 70rpx;
					margin-right: 20rpx;
					position: relative;
					z-index: 1;
				}

				&__content {
					font-size: 30rpx;

					&--data {
						margin-top: 5rpx;
						font-size: 24rpx;
						// font-weight: bold;
					}
				}
			}

			&__right {
				&--icon {
					position: absolute;
					right: 0upx;
					top: 50upx;
					font-size: 100upx;
					width: 108upx;
					height: 108upx;
					text-align: center;
					line-height: 60upx;
					opacity: 0.1;
				}
			}
		}
	}

	.choose-tab {
		display: flex;
		flex-flow: row;
		justify-content: space-between;
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		border-bottom: 2rpx solid #ccc;
		padding: 0 130rpx;
		box-sizing: border-box;
	}

	.choose-tab-item {
		width: 25%;
	}

	.active {
		color: red;
		border-bottom: 4rpx solid red;
	}

	.content {
		text-align: center;
	}

	.chat-custom-right {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: space-between;
		align-items: flex-end;
	}

	.chat-custom-text {
		font-size: 12px;
		color: #999;
	}

	.news_list {
		max-width: 700rpx;
		display: flex;
		margin: 0 auto;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1rpx solid #fff3f3;
		padding: 20rpx 0;
		box-sizing: content-box;


		.news_list_left {
			width: 160rpx;
			height: 130rpx;
			// margin-right: 30rpx;

			img {
				width: 100%;
				height: 100%;
				border-radius: 10rpx;
			}
		}

		.news_list_right {
			width: 510rpx;
			// height: 150rpx;
			// background-color: pink;

			.news_list_head {
				text-overflow: ellipsis;
				overflow: hidden;
				white-space: nowrap;
				width: 500rpx;
				font-size: 32rpx;
				// color: #6d6a6a;
			}

			.news_list_con {
				// text-align: left;
				// display: -webkit-box;
				// -webkit-box-orient: vertical;
				// -webkit-line-clamp: 2;
				// overflow: hidden;
				// text-overflow: ellipsis;
				text-overflow: ellipsis;
				overflow: hidden;
				white-space: nowrap;
				width: 520rpx;
				font-size: 26rpx;
				color: #6d6a6a;
				text-align: left;
				margin: 10rpx 0;
			}

			.news_list_bottom {
				display: flex;
				align-items: center;
				// justify-content: space-between;
				margin-bottom: 10rpx;
				color: #6d6a6a;
				font-size: 24rpx;
			}
		}
	}

	.news_list2 {
		max-width: 680rpx;
		.news_list_left2 {
			width: 120rpx;
			height: 120rpx;
			border-radius: 50%;
			overflow: hidden;
		}

		.news_list_right2 {
			.news_list_head2 {
				text-overflow: ellipsis;
				overflow: hidden;
				white-space: nowrap;
				width: 540rpx;
				font-size: 32rpx;
				margin-bottom: 20rpx;
				text-align: left;

			}

			.news_list_con2 {
				text-align: left;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
				text-overflow: ellipsis;
				color: #6d6a6a;

			}
		}
	}

	.lunbotu {
		position: relative;

	}

	.indication {
		position: absolute;
		left: 0;
		bottom: 40rpx;
	}
.tn-color-black-title{
		font-size: 32rpx;
	}
	/* 业务展示 end */
</style>